package com.jz.community.modulemine.money.presenter;

import com.jz.community.basecomm.mvp.BaseLifeCyclePresent;
import com.jz.community.basecomm.net.rxandroid.OnLoadListener;
import com.jz.community.modulemine.money.bean.PurchaseInfoBean;
import com.jz.community.modulemine.money.model.MoneyModel;
import com.jz.community.modulemine.money.model.MoneyModelImp;
import com.jz.community.modulemine.money.ui.MoneyPurchaseView;

public class MoneyPurchasePresenter extends BaseLifeCyclePresent<MoneyPurchaseView.View> implements MoneyPurchaseView.Presenter {

    private MoneyPurchaseView.View view;
    private MoneyModel moneyModel;

    public MoneyPurchasePresenter(MoneyPurchaseView.View view) {
        this.view = view;
        this.moneyModel = new MoneyModelImp(view.getContext());
    }

    @Override
    public void initPurchaseData() {
        moneyModel.initPurchaseInfo(new OnLoadListener<PurchaseInfoBean>() {
            @Override
            public void onSuccess(PurchaseInfoBean purchaseInfoBean) {
                view.initPurchaseDataSuccess(purchaseInfoBean);
            }

            @Override
            public void onFail(String msg, int code) {
                if (code == 404) {
                    view.noPurchaseData();
                } else {
                    view.initPurchaseDataFail(msg);
                }


            }
        });
    }

    @Override
    public void purchaseMoney(String company, String count, String name, String phone, String address, String mail) {
        moneyModel.purchaseMoney(company, count, name, phone, address, mail, new OnLoadListener<PurchaseInfoBean>() {
            @Override
            public void onSuccess(PurchaseInfoBean purchaseInfoBean) {
                view.purchaseMoneySuccess(purchaseInfoBean);
            }

            @Override
            public void onFail(String msg, int code) {
                view.purchaseMoneyFail(msg);

            }
        });

    }
}
